
*** HOUSEHOLD AND MEDICAL CONTROLS COLLECTED AT 7

use "Data/NCDS/UKDA-5565-stata11/stata11/ncds0123.dta", clear
label variable n1region "1P Region at NCDS1 (1965) - 7 years"
qui ds, not(varl "ncdsid serial number"|varl "1P*" |varl "1M*")
drop `r(varlist)'

label define nym 0 "No" 1 "Yes" 99 "Missing", replace

* rename serial number
rename ncdsid  NCDSID  

* region at 7 (missing coded as 99)
rename n1region region_7
recode region_7 (-1=99) (.=99)
label define n1region  3 "E and W Riding" 99 "Missing", modify
label values region_7 n1region

* kids in hh
rename n99 ikidshh_7
recode ikidshh_7 (-1=.)
winsor ikidshh_7, generate(kidshh_7) p($p_winsior)
drop ikidshh_7
label variable kidshh_7 "Number of children aged under 21 in the household" 
ge MissingKH_7=kidshh_7==.
label variable MissingKH_7 "Missing number of children under 21 in the household"
su kidshh_7
replace kidshh_7=r(mean) if MissingKH_7==1

* parents was child to stay on in education
rename  n116 parentwanted_7
recode parentwanted_7 (-1 4=99) (3=0) (2=1) (1=2)
label define pw7 0 "No" 1 "Yes" 2 "Don't know" 99 "Missing"
label values parentwanted_7 pw7

* mother reads to child 
rename n179 motherread_7
recode motherread_7 (-1=99) (.=99) (1=99)
label define n179  99 "Missing", modify
label define n179  2 "At least every week", modify
label define n179  3 "Occasionally", modify
label define n179  4 "Never or hardly ever", modify

* father reads to child 
rename n180 fatherread_7
recode fatherread_7 (-1=99) (.=99) (1=99) 
label define n180  99 "Missing", modify
label define n180  2 "At least every week", modify
label define n180  3 "Occasionally", modify
label define n180  4 "Never or hardly ever", modify

* mother goes on outlings with child
rename n181 motheroutings_7
recode motheroutings_7 (-1 1 .=99) 
label define n181 99 "Missing", modify
label define n181  2 "Most weeks", modify
label define n181  3 "Occasionally", modify
label define n181  4 "Never or hardly ever", modify

* father goes on outings with child
rename n182 fatheroutings_7
recode fatheroutings_7 (-1 1 .=99) 
label define n182 99 "Missing", modify
label define n182  2 "Most weeks", modify
label define n182  3 "Occasionally", modify
label define n182  4 "Never or hardly ever", modify

* dad's role in managing the child
rename n183 dadsrole_7
recode dadsrole_7 (-1 . 1 =99)
label define n183 99 "Missing", modify
label define n183 2 "Father's role bigger or equal", modify
label define n183 3 "Father's role smaller but significant", modify
label define n183 4 "Father's role very small or zero", modify

* social class of father 
rename n190 fathersc_7
recode fathersc_7 (-1=99) (.=99) (1=7) (2=1) (3=2) (4=3) (5=4) (6 7=5) (8=6)
label define fsc7  1 "I" 2 "II" 3 "IIIN" 4 "IIIM" 5 "IV" 6 "V" 7 "Mother single" 99 "Missing", replace
label values fathersc_7 fsc7

* father stayed in school beyond comp. sch leaving age
ge fatherpostcompeduc_7=1 if n194==2
replace fatherpostcompeduc_7=0 if  n194==3
replace fatherpostcompeduc_7=99 if fatherpostcompeduc_7==.
label values fatherpostcompeduc_7 nym  

* age father left school (assume 15 is did not stay on)
rename n195 ifatherageleftsch_7
replace ifatherageleftsch_7=15 if fatherpostcompeduc_7==0 
replace ifatherageleftsch_7=99 if fatherpostcompeduc_7==99 
replace ifatherageleftsch_7=15 if fatherpostcompeduc_7==1 & ifatherageleftsch_7<15
replace ifatherageleftsch_7=21 if ifatherageleftsch_7>21 &  ifatherageleftsch_7!=. & ifatherageleftsch_7!=99
recode ifatherageleftsch_7 (99 = .)
winsor ifatherageleftsch_7, generate(fatherageleftsch_7) p($p_winsior)
drop ifatherageleftsch_7
label variable fatherageleftsch_7 "Father's age when he finished full-time education"

* recode for consistency
replace fatherpostcompeduc_7=0 if fatherageleftsch_7==15

* recode age father left school with mean (fatherpostcompeduc_7 includes dummy for missing)
su fatherageleftsch_7 if fatherpostcompeduc_7!=99
replace fatherageleftsch_7=r(mean) if fatherpostcompeduc_7==99

* mother worked before child started school
rename n197 motherworkb4sch_7
recode motherworkb4sch_7 (-1=99) (.=99) (1=99)
label define n197 99 "Missing", modify
label define n197 2 "Part-time or temporary", modify


* mother worked after child started school
rename n147 motherworkafsch_7
recode motherworkafsch_7   (-1=99) (.=99) (1=99)
label define n147 99 "Missing", modify
label define n147 2 "Part-time or temporary", modify

* housing tenure (owned, rented, council house, etc.)
rename n200 housetenure_7
recode  housetenure_7 (-1=99) (.=99) (1=99) (5=6)
label define n200 99 "Missing", modify

* rooms in house (excluding kitchen and bathrooms)
rename n201 iroomsinhouse_7
replace iroomsinhouse_7=. if iroomsinhouse_7<0
winsor iroomsinhouse_7, generate(roomsinhouse_7) p($p_winsior)
drop iroomsinhouse_7
label variable roomsinhouse_7 "Number of rooms in the home" 
ge MissingRH_7=roomsinhouse_7==.
label variable MissingRH_7 "Missing number of rooms in the home"
su roomsinhouse_7
replace roomsinhouse_7=r(mean) if MissingRH_7==1

* breast feeding duration
rename n222 breatfed_7
recode breatfed_7 (-1=99) (.=99) (1=99)
label define n222 99 "Missing", modify
label var breatfed_7 "Breast feeding duration for cohort member"
label define n222 2 "Zero" 3 "Positive but under one month" 4 "Over one month"  99 "Missing", modify


* financial difficulities
rename n315 financialdiff_7
recode financialdiff_7 (. -1 1=99) (2=1) (3=0)
label values financialdiff_7 nym

********************************************************************************
* Variables collected from a medical examination by a doctor
********************************************************************************

* speech
rename n386 speech_7
recode speech_7 (-1 1 .=99) (4 5=3)
label define n386 99 "Missing" 2 "Normal" 3 "Deficient", modify

* hearing
rename n389 hearing_7
recode hearing_7 (-1 1 .=99) (4 5=3) 
label define n389 99 "Missing" 2 "Normal" 3 "Deficient", modify

* vision
rename n382 vision_7
recode vision_7 (-1 1 .=99) (4 5 6 7=3)
label define n382 99 "Missing" 2 "Normal" 3 "Deficient", modify

* Generate labeled indicators
local catvar region_7  parentwanted_7 motherread_7  fatherread_7 motheroutings_7  fatheroutings_7 dadsrole_7 fathersc_7 fatherpostcompeduc_7 motherworkb4sch_7 motherworkafsch_7 ///
 housetenure_7  breatfed_7 financialdiff_7 speech_7 hearing_7 vision_7
foreach r of local catvar{
	indicators `r'
}

keep NCDSID *_7*
sort NCDSID 

save scratchdata/ncds0123_HDcontrols7.dta, replace

